package com.wz.jiangsu.main.test1;


import java.time.LocalDateTime;

public class Test {

    Object obj = new Object();

    public static void main(String[] args) throws Exception{

        getSzize(9);

        String str = "abcsfdf";

        String target = "bc";

        int index = getIndexFromStr(str,target);

        for (int i = 0; i < 5; i++) {
            System.out.println("111");
            new Thread(()->{
                System.out.println(Thread.currentThread().getName() + " :today is " + LocalDateTime.now());
            }).start();
        }
        Thread.sleep(4000L);




        System.out.println("index = " + index);
    }

    private static void getSzize(int size) throws InterruptedException {
        synchronized(Test.class) {
            for (int j = 1; j <= size ; j++) {
                if (j % 2 != 0) {
                    System.out.println("奇数:" + Thread.currentThread().getName() + " :" + j);
                    Test.class.wait();
                }
            }
        }

        synchronized(Test.class) {
            for (int j = 1; j <= size ; j++) {
                if (j % 2 == 0) {
                    System.out.println("偶数" + Thread.currentThread().getName() + " :" + j);
                    Test.class.notify();
                }
            }
        }
    }

    private static int getIndexFromStr(String str, String target) {

        if (!str.contains(target)) {
            return -1;
        } else {
            for (int i = 0; i < str.length(); i++) {
                if (str.charAt(i) == target.charAt(0)) {
                    return i;
                }

            }
        }
        return -1;
    }


}
